package com.gxa.service.impl;

import com.gxa.common.PaginationResult;
import com.gxa.mapper.SupplierzMapper;
import com.gxa.pojo.Supplierz;
import com.gxa.service.SupplierzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * User: zrf
 * Date: 2020/10/29 17:18
 * Description:
 * Version: V1.0
 */
@Service
public class SupplierzServicecImpl implements SupplierzService{
    @Autowired(required = false)
    private SupplierzMapper supplerzMapper;
    /**
     * 查询供应商
     *
     * @param
     * @return 实例对象
     */
    @Override
    public PaginationResult querySupp(Integer currentPage, Integer pageSize) {
        PaginationResult paginationResult = new PaginationResult();
        Integer parm1 = (currentPage - 1) * pageSize;
        paginationResult.setData(supplerzMapper.querySupp(parm1,pageSize));
        paginationResult.setCurrentPage(parm1);
        paginationResult.setPageSize(pageSize);
        int total = suppCont() / pageSize;
        System.out.println(suppCont());
        if(suppCont() % pageSize != 0){
            total+=1;
        }
        System.out.println(total);
        paginationResult.setTotalPage(total);
        paginationResult.setTotalSize(suppCont());
        return paginationResult;
    }

    /**
     * 根据名字搜索供应商
     *
     * @param
     * @return 实例对象
     */
    @Override
    public Supplierz selSuppByName(String suppliersName) {
        return supplerzMapper.selSuppByName(suppliersName);
    }

    /**
     * 添加供应商
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int addSupp(Supplierz supplierz) {
        return supplerzMapper.addSupp(supplierz);
    }
    /**
     * 修改供应商
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int updateSupp(Supplierz supplierz) {
        return supplerzMapper.updateSupp(supplierz);
    }

    /**
     * 删除供应商
     *
     * @param
     * @return 实例对象
     */
    @Override
    public int delSupp(Integer suppliersId) {
        return supplerzMapper.deleteById(suppliersId);
    }

    /**
     * 查询供应商总数
     *
     * @param
     * @return 实例对象
     */
    private int suppCont(){
        return supplerzMapper.suppCont();
    }
}
